//
//  NSBundle+YCTools.m
//  YCBaseModule
//
//  Created by Apple on 2023/4/18.
//

#import "NSBundle+YCTools.h"

@implementation NSBundle (YCTools)

+ (NSBundle *)yc_ResourceBundle:(NSString *)bundleName {
    NSString *resourceBundlePath = [[NSBundle mainBundle] pathForResource:bundleName ofType:@"bundle"];
    NSBundle *resourceBundle = [NSBundle bundleWithPath:resourceBundlePath];
    
    return resourceBundle;
}

+ (NSBundle *)yc_ResourceBundle:(NSString *)bundleName frameworkName:(nullable NSString *)frameworkName {
    NSString *resourceBundlePath = [[NSBundle mainBundle] pathForResource:bundleName ofType:@"bundle"];
    NSBundle *resourceBundle = [NSBundle bundleWithPath:resourceBundlePath];
    
    if (!resourceBundle)
    {
        NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"Frameworks" withExtension:nil];
        bundleURL = [bundleURL URLByAppendingPathComponent:frameworkName];
        bundleURL = [bundleURL URLByAppendingPathExtension:@"framework"];
        
        NSBundle *imageBundle = [NSBundle bundleWithURL:bundleURL];
        bundleURL = [imageBundle URLForResource:bundleName withExtension:@"bundle"];
        resourceBundle = [NSBundle bundleWithURL:bundleURL];
    }
    
    return resourceBundle;
}

@end
